#include <stdio.h>
int inf = 9999999;
int u[100000],v[100000],w[100000],first[100000],next[100000];
int main()
{
    int n, m, r, a, b, c, k, i, j;
    scanf("%d%d%d", &n, &m, &r);
    /*for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            if (i == j)
                u[i]=0,v[j]=0;
            else
                e[i][j] = inf;*/
    for(i=0;i<=n;i++)
        first[i]=-1;
    for (i = 0; i < m; i++)
    {
        scanf("%d%d%d", &u[i], &v[i], &w[i]);
        next[i]=first[u[i]];
        first[u[i]]=i;
        
    }
    for (k = 0; k < n; k++)
        for (i = 0; i < n; i++)
            if (e[r][k] < inf && e[k][i] < inf && e[r][i] > e[r][k] + e[k][i])
                e[r][i] = e[r][k] + e[k][i];
    for (i = 0; i < n; i++)
    {
        if (e[r][i] != inf)
            printf("%d\n", e[r][i]);
        else
            printf("INF\n");
    }
    return 0;
}